package com.Test;

import com.Cclass;
import com.CclassMapper;
import com.mapper.StudentsMapper;
import com.pojo.Students;

import javax.net.ssl.HandshakeCompletedEvent;

public class StudentsTest {
    @Test
    public <SqlSession> void findStudentsByIdTest() {
        HandshakeCompletedEvent MyBatisUtils = null;
        SqlSession sqlSession = (SqlSession) MyBatisUtils.getSession();
        StudentsMapper mapper = sqlSession.getMapper(StudentsMapper.class);
        Students students = mapper.selectStudentById(2);
        System.out.println(students.toString());
        sqlSession.close();
    }
    @Test
    public <SqlSession> void findStudentsByNameTest() {
        HandshakeCompletedEvent MyBatisUtils = null;
        SqlSession sqlSession = (SqlSession) MyBatisUtils.getSession();
        StudentsMapper mapper = sqlSession.getMapper(StudentsMapper.class);
        Students students = new Students();
        students.setId(4);
        students.setName("李雷");
        students.setAge(21);
        int count = mapper.updateStudentById(students);
        if (count > 0){
            System.out.println("更新成功");
        }else{
            System.out.println("更新失败");
        }
        System.out.println(students.toString());
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public <SqlSession> void findStudentsBysIdTest() {
        HandshakeCompletedEvent MyBatisUtils = null;
        SqlSession sqlSession = (SqlSession) MyBatisUtils.getSession();
        CclassMapper mapper = sqlSession.getMapper(CclassMapper.class);
        Cclass cclass = mapper.selectClassaById(2);
        System.out.println(cclass.toString());
        sqlSession.close();
    }
}
